/**
 * 添加布局页面 ckl on 2015/11/6.
 */
function addControl(house_id){
    $("#addControl").modal();       
}
//返回操作
function delLayout(){
    location.reload();
}

//表单提交操作
function controlFrom(){
    var building_num=$("#building_num").val();
    var floor=$("#floor").val();
    var room_num=$("#room_num").val();
    var house_room=$("#house_room").val();
    if(building_num==''|| building_num==null){
        $("#house_control_error").html("请输入楼幢号");
        return false;
    }
    if(floor==''|| floor==null){
        $("#house_control_error").html("请输入层数");
        return false;
    }
    if(room_num==''|| room_num==null){
        $("#house_control_error").html("请输入每单元/层房间数");
        return false;
    }
//    if(house_room==''|| house_room==null){
//        $("#house_control_error").html("请输入初始房号");
//        return false;
//    }
   
    $("#controlFrom").submit();
}


//销控管理
function controlManager(id){
    $("#al_add").empty();
    $.ajax({
        type:"GET",
        dataType:"json",
        data:{"id":id},
        url:"/index.php?r=control/getcontrollist",
        success:function(data) {
            var data=eval(data);
            for(var i=0;i<data.length;i++){
                $("#al_add").append("<a href='#' onclick='selControlLink(\""+data[i]['id']+"\")' class='control_detail_a icon-btn span2 "+data[i]['status_class']+"' id='"+data[i]['id']+"'>"+data[i]['house_room']+"</a>");
            }
        }
    });
    $("#controlManager").modal();       
}
//更改销控明细状态：选择销控明细
function selControlLink(id){
    var selDetailAll=$("#selDetailAll").val();
    if(selDetailAll){
        selDetailAll+=","+id;
    }else{
        selDetailAll=id;        
    }
    $("#selDetailAll").val(selDetailAll);
}
//设置销控状态
function setControlStatus(status){
    var idAll=$("#selDetailAll").val();
    $.ajax({
        type:"GET",
        dataType:"json",
        data:{"status":status,"idAll":idAll},
        url:"/index.php?r=control/setcontrolstatus",
        success:function(data) {
            var data=eval(data);
            if(data.code==200){
                $("#control_detail_msg").html("设置成功!");
                delLayout();
            }else{
                $("#control_detail_msg").html("设置失败!");                
            }
        }
    });
}

//编辑销控
function controlUpdate(id){
    $("#al_up").empty();
    $.ajax({
        type:"GET",
        dataType:"json",
        data:{"id":id},
        url:"/index.php?r=control/getcontrollist",
        success:function(data) {
            var data=eval(data);
            for(var i=0;i<data.length;i++){
                $("#al_up").append("<a href='#' onclick='upControlLink(\""+data[i]['id']+"\")' class='control_detail_a icon-btn span2 "+data[i]['status_class']+"' id='"+data[i]['id']+"'>"+data[i]['house_room']+"</a>");
            }
        }
    });
    $("#controlUpdate").modal();       
}
//编辑页面销控明细状态：选择销控明细
function upControlLink(id){
    var upDetailAll=$("#upDetailAll").val();
    if(upDetailAll){
        upDetailAll+=","+id;
    }else{
        upDetailAll=id;        
    }
    $("#upDetailAll").val(upDetailAll);
}
//编辑销控状态
function upControlStatus(status){
    var idAll=$("#upDetailAll").val();
    $.ajax({
        type:"GET",
        dataType:"json",
        data:{"status":status,"idAll":idAll},
        url:"/index.php?r=control/setcontrolstatus",
        success:function(data) {
            var data=eval(data);
            if(data.code==200){
                $("#control_detail_up_msg").html("设置成功!");
                delLayout();
            }else{
                $("#control_detail_up_msg").html("设置失败!");                
            }
        }
    });
}




//销控区域配置页面
function addControlArea(house_id){
    $("#al_area_add").empty();
    $.ajax({
        type:"GET",
        dataType:"json",
        data:{"house_id":house_id},
        url:"/index.php?r=control/getcontrolarealist",
        success:function(data) {
            var data=eval(data);
            for(var i=0;i<data.length;i++){
                $("#al_area_add").append("<a href='#' class='control_detail_area icon-btn span2 ' id='area_"+data[i]['id']+"'>"+data[i]['area_name']+"<span class='badge badge-important' onclick='deleControlArea(\""+data[i]['id']+"\")'>×</span></a>");
            }
        }
    });
    $("#addControlArea").modal();      
}
//新增片区
function  controlAreaFrom(){
    var control_area_data=$("#control_area_data").val();    
    if(control_area_data==''|| control_area_data==null){
        $("#house_control_area_error").html("请输入片区名称");
        return false;
    }
    $("#controlAreaFrom").submit();
}
//删除销控片区
function deleControlArea(id){
    $.ajax({
        type:"POST",
        dataType:"json",
        data:{"id":id},
        url:"/index.php?r=control/delecontrolarea",
        success:function(data) {
            var data=eval(data);
            if(data['state']==1){//删除成功
                $("#area_"+id).remove();             
            }
            $("#house_control_area_error").html(data['str']);                
        }
    });
}
//添加新片区
function addControlAreaInfo(){
    $("#selControlAreaInfo").hide();
    $("#addControlAreaInfo").show();
}
//选择旧片区
function selControlAreaInfo(){
    $("#selControlAreaInfo").show();
    $("#addControlAreaInfo").hide();
    
}